<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Binds a PHP array to an Oracle PL/SQL array parameter</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.oci8.html">OCI8 函数</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.oci-bind-by-name.html">oci_bind_by_name</a></div>
 <div class="up"><a href="ref.oci8.html">OCI8 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.oci-bind-array-by-name" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">oci_bind_array_by_name</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.2, PECL OCI8 &gt;= 1.2.0)</p><p class="refpurpose"><span class="refname">oci_bind_array_by_name</span> &mdash; <span class="dc-title">Binds a PHP array to an Oracle PL/SQL array parameter</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.oci-bind-array-by-name-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>oci_bind_array_by_name</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$statement</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$var_array</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$max_table_length</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$max_item_length</code><span class="initializer"> = -1</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code><span class="initializer"> = SQLT_AFC</span></span>
  ]] )</div>

  <p class="para rdfs-comment">
   Binds the PHP array <em><code class="parameter">var_array</code></em> to the Oracle
   placeholder <em><code class="parameter">name</code></em>, which points to an Oracle PL/SQL
   array. Whether it will be used for input or output will be determined at
   run-time. 
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.oci-bind-array-by-name-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">statement</code></em></dt>

     <dd>

      <p class="para">
       A valid OCI statement identifier.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">name</code></em></dt>

     <dd>

      <p class="para">
       The Oracle placeholder.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">var_array</code></em></dt>

     <dd>

      <p class="para">
       An array.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">max_table_length</code></em></dt>

     <dd>

      <p class="para">
       Sets the maximum length both for incoming and result arrays.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">max_item_length</code></em></dt>

     <dd>

      <p class="para">
       Sets maximum length for array items. If not specified or equals to -1,
       <span class="function"><strong>oci_bind_array_by_name()</strong></span> will find the longest
       element in the incoming array and will use it as the maximum length.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">type</code></em></dt>

     <dd>

      <p class="para">
       Should be used to set the type of PL/SQL array items. See list of
       available types below:
      </p>
      <p class="para">
       <ul class="itemizedlist">
        <li class="listitem">
         <p class="para">
          <strong><code>SQLT_NUM</code></strong> - for arrays of NUMBER.
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>SQLT_INT</code></strong> - for arrays of INTEGER (Note: INTEGER
          it is actually a synonym for NUMBER(38), but
          <strong><code>SQLT_NUM</code></strong> type won&#039;t work in this case even
          though they are synonyms).
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>SQLT_FLT</code></strong> - for arrays of FLOAT.
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>SQLT_AFC</code></strong> - for arrays of CHAR.
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>SQLT_CHR</code></strong> - for arrays of VARCHAR2.
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>SQLT_VCS</code></strong> - for arrays of VARCHAR.
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>SQLT_AVC</code></strong> - for arrays of CHARZ.
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>SQLT_STR</code></strong> - for arrays of STRING.
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>SQLT_LVC</code></strong> - for arrays of LONG VARCHAR.
         </p>
        </li>
       <li class="listitem">
         <p class="para">
          <strong><code>SQLT_ODT</code></strong> - for arrays of DATE.
         </p>
        </li>
       </ul>
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.oci-bind-array-by-name-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.oci-bind-array-by-name-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1914">
    <p><strong>Example #1 <span class="function"><strong>oci_bind_array_by_name()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$c&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"scott"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"tiger"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$create&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"CREATE&nbsp;TABLE&nbsp;bind_example(name&nbsp;VARCHAR(20))"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$statement&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$create</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$statement</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$create_pkg&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"<br />CREATE&nbsp;OR&nbsp;REPLACE&nbsp;PACKAGE&nbsp;ARRAYBINDPKG1&nbsp;AS<br />&nbsp;&nbsp;TYPE&nbsp;ARRTYPE&nbsp;IS&nbsp;TABLE&nbsp;OF&nbsp;VARCHAR(20)&nbsp;INDEX&nbsp;BY&nbsp;BINARY_INTEGER;<br />&nbsp;&nbsp;PROCEDURE&nbsp;iobind(c1&nbsp;IN&nbsp;OUT&nbsp;ARRTYPE);<br />END&nbsp;ARRAYBINDPKG1;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$statement&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$create_pkg</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$statement</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$create_pkg_body&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"<br />CREATE&nbsp;OR&nbsp;REPLACE&nbsp;PACKAGE&nbsp;BODY&nbsp;ARRAYBINDPKG1&nbsp;AS<br />&nbsp;&nbsp;CURSOR&nbsp;CUR&nbsp;IS&nbsp;SELECT&nbsp;name&nbsp;FROM&nbsp;bind_example;<br />&nbsp;&nbsp;PROCEDURE&nbsp;iobind(c1&nbsp;IN&nbsp;OUT&nbsp;ARRTYPE)&nbsp;IS<br />&nbsp;&nbsp;&nbsp;&nbsp;BEGIN<br />&nbsp;&nbsp;&nbsp;&nbsp;FOR&nbsp;i&nbsp;IN&nbsp;1..5&nbsp;LOOP<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;INSERT&nbsp;INTO&nbsp;bind_example&nbsp;VALUES&nbsp;(c1(i));<br />&nbsp;&nbsp;&nbsp;&nbsp;END&nbsp;LOOP;<br />&nbsp;&nbsp;&nbsp;&nbsp;IF&nbsp;NOT&nbsp;CUR%ISOPEN&nbsp;THEN<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OPEN&nbsp;CUR;<br />&nbsp;&nbsp;&nbsp;&nbsp;END&nbsp;IF;<br />&nbsp;&nbsp;&nbsp;&nbsp;FOR&nbsp;i&nbsp;IN&nbsp;REVERSE&nbsp;1..5&nbsp;LOOP<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FETCH&nbsp;CUR&nbsp;INTO&nbsp;c1(i);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IF&nbsp;CUR%NOTFOUND&nbsp;THEN<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CLOSE&nbsp;CUR;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EXIT;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END&nbsp;IF;<br />&nbsp;&nbsp;&nbsp;&nbsp;END&nbsp;LOOP;<br />&nbsp;&nbsp;END&nbsp;iobind;<br />END&nbsp;ARRAYBINDPKG1;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$statement&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$create_pkg_body</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$statement</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$statement&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"BEGIN&nbsp;ARRAYBINDPKG1.iobind(:c1);&nbsp;END;"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$array&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"one"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"two"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"three"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"four"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"five"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">oci_bind_array_by_name</span><span style="color: #007700">(</span><span style="color: #0000BB">$statement</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">":c1"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$array</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SQLT_CHR</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$statement</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.oci8.html">OCI8 函数</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.oci-bind-by-name.html">oci_bind_by_name</a></div>
 <div class="up"><a href="ref.oci8.html">OCI8 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
